﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MBSDAL;

namespace MBSBusinessEntities
{
    public class FoodOrderBE:ICrud
    {
        public FoodOrderBE()
        {
            this.mbs = new MBS_Entities();
        }

        #region ClassVariables
        
        private MBS_Entities mbs;
        private int _OrderID;
        private int _BookingID;
        private string _ItemsOrdered;
        private decimal _Price;
                
        #endregion


        #region Properties
        public int OrderID
        {
            get { return _OrderID; }
            set { _OrderID = value; }
        }

        public int BookingID
        {
            get { return _BookingID; }
            set { _BookingID = value; }
        }

        public string ItemsOrdered
        {
            get { return _ItemsOrdered; }
            set { _ItemsOrdered = value; }
        }

        public decimal Price
        {
            get { return _Price; }
            set { _Price = value; }
        }
        #endregion


        #region Methods

        private FoodOrderBE ConvertToEntity(FoodOrder foodorderItem)
        {
            FoodOrderBE foodOrderEntity = new FoodOrderBE();
            foodOrderEntity.BookingID = foodorderItem.BookingID;
            foodOrderEntity.OrderID = foodorderItem.OrderID;
            foodOrderEntity.ItemsOrdered = foodorderItem.ItemsOrdered;
            foodOrderEntity.Price = Convert.ToDecimal(foodorderItem.Amount);
            return foodOrderEntity;
        }


        public bool Add()
        {
            FoodOrder foodOrderEntity = new FoodOrder();
            foodOrderEntity.BookingID = this.BookingID;
            foodOrderEntity.OrderID = this.OrderID;
            foodOrderEntity.ItemsOrdered = this.ItemsOrdered;
            foodOrderEntity.Amount = this.Price;
            mbs.AddToFoodOrders(foodOrderEntity);
            mbs.SaveChanges();
            return true;
        }

        public bool Delete(int id)
        {
            throw new NotImplementedException();
        }

        public bool Update()
        {
            throw new NotImplementedException();
        }

        public object GetByID(int id)
        {
            return ConvertToEntity(getDALFoodorderbyID(id));
        }

        private FoodOrder getDALFoodorderbyID(int id)
        {
            FoodOrder foodOrder = new FoodOrder();
            foodOrder = mbs.FoodOrders.First(X => X.OrderID == id);
            return foodOrder;
        }
        #endregion
    }
}
